#[cfg(test)]
mod tests {
    struct ImportantExcerpt<'a> {
        part: &'a str,
    }

    impl<'a> ImportantExcerpt<'a> {
        fn announce_and_return_part(&self, announcement: &str) -> &str {
            println!("Attention: {}", announcement);
            self.part
        }
    }

    #[test]
    fn test_struct_lifetime() {
        let novel = String::from("Call me Ishmael. Some years ago...");
        let first_sentence = novel.split('.').next().unwrap();
        let i = ImportantExcerpt {
            part: first_sentence,
        };
        assert_eq!(i.announce_and_return_part("Important notice"), "Call me Ishmael");
    }

    fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
        if x.len() > y.len() { x } else { y }
    }

    #[test]
    fn test_function_lifetime() {
        let s1 = String::from("abcd");
        let s2 = "xyz";
        let result = longest(s1.as_str(), s2);
        assert_eq!(result, "abcd");
    }
}